-
Notifications
You must be signed in to change notification settings - Fork 8
feat(nodejs): protocol version option, binary protocol for doubles #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for protocol version negotiation and binary serialization of double values in the QuestDB Node.js client. The main changes include making configuration parsing asynchronous to support HTTP endpoint queries, adding a new binary protocol (version 2) for more efficient double encoding, and restructuring the buffer implementation with version-specific classes.
- Adds
protocol_version
configuration option with support for 'auto', '1', and '2' values - Implements binary serialization for doubles in protocol version 2 vs text serialization in version 1
- Makes
Sender.fromConfig()
andSenderOptions.fromConfig()
async to support server version negotiation
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
test/util/mockhttp.ts | Adds settings endpoint mock and protocol version configuration support |
test/sender.transport.test.ts | Updates all test calls to use async Sender.fromConfig and adds protocol_version parameters |
test/sender.integration.test.ts | Converts Sender constructor calls to use SenderOptions.resolveAuto for proper version resolution |
test/sender.config.test.ts | Updates configuration tests to be async and adds protocol_version to all test cases |
test/sender.buffer.test.ts | Adds protocol_version parameter to all Sender constructor calls in tests |
test/options.test.ts | Extensive updates to test protocol version parsing, validation, and HTTP endpoint negotiation |
src/utils.ts | Adds fetchJson utility function for HTTP requests |
src/sender.ts | Makes fromConfig and fromEnv methods async, changes buffer creation to use factory pattern |
src/options.ts | Adds protocol version parsing, validation, and automatic resolution via HTTP settings endpoint |
src/buffer/index.ts | Refactors to interface-based design with factory function for version-specific buffer creation |
src/buffer/bufferv2.ts | Implements binary double serialization for protocol version 2 |
src/buffer/bufferv1.ts | Implements text-based serialization for protocol version 1 (existing behavior) |
src/buffer/base.ts | Moves common buffer functionality to abstract base class |
src/options.ts
Outdated
const url = `${options.protocol}://${options.host}:${options.port}/settings`; | ||
const settings: { | ||
config: { LINE_PROTO_SUPPORT_VERSION: number[] }; | ||
} = await fetchJson(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we have a self-signed certificate configured? Then this HTTP request will fail while the subsequent ILP requests would have succeeded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 812d5b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any new/existing tests around that?
abstract floatColumn(name: string, value: number): SenderBuffer; | ||
|
||
/** | ||
* Writes an integer column with its value into the buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should probably mention that this method writes 64-bit integer and that it works for long
and smaller integer database types.
} | ||
|
||
/** | ||
* Writes a float column with its value into the buffer using v1 serialization (text format). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should probably mention that this method writes 64-bit FP number and that it works for double
and float
database types.
src/utils.ts
Outdated
): Promise<T> { | ||
const controller = new AbortController(); | ||
const { signal } = controller; | ||
setTimeout(() => controller.abort(), timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should cancel this timeout with clearTimeout
when await fetch()
executes successfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added clearTimeout()
in 97066b4
Support for sending doubles as binary, and resolving the protocol version option.